<?php

/**
 * This function checks if a given string is a valid base64 encoded one
 *
 * @access   public
 * @author   Svilen
 *
 * @param    string   $string       Base64 encoded string
 *
 * @return   boolean                Returns TRUE fi the string is a valid base64 encoded and FALSE if it not a valid one
 *
 * @since    22-06-2005
 * @version  1.0
 *
 */
function is_base64_encoded ($string = '') {
	$length = strlen($string);
  
  if (empty($string)) {
  	return FALSE;
  }
  
  // Check if the string length is divisible by 4
  if (($length % 4) > 0) {
  	return FALSE;
  }
  
  // Check for not allowed chars
  if (!preg_match('/^([a-zA-Z0-9=+\/])*$/', $string)) {
  	return FALSE;
  }
  
  // Check if = is only at the end or at the start of the string
  if (strpos (substr($string, 2, ($length - 4)),  '=') > 0) {
  	return FALSE;
  }
  
  return TRUE;
}

?>